<!-- 日期区间 -->
<template>
  <block>
    <van-field
      :value="form[name]"
      :required="!norequired"
      clickable
      :label="label"
      :placeholder="placeholder"
      readonly
      is-link
      @click-input="dateShow = true"
    ></van-field>
    <van-calendar
      :show="dateShow"
      @close="onDateClose"
      @confirm="onDateConfirm"
      :minDate="minDate"
      type="range"
    />
  </block>
</template>
<script>
export default {
  props: {
    form: Object, //需要修改的数据
    label: String,
    placeholder: String,
    name: String,
    norequired: Boolean, // 默认是false 不影响其他的 这个
  },
  data(){
    return{
        dateShow:false,
        minDate: new Date(2020, 0, 1).getTime(),
    }
  },
  methods:{
    formatDate(date) {
      date = new Date(date);
      return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`;
    },
    changeDate() {
      this.dateShow = true;
    },
    onDateConfirm(date) {
      console.log(date,'日期');
      var start_date = this.formatDate(date.detail[0]);
      var end_date = this.formatDate(date.detail[1]);
    //   this.$emit("click-input",  this.form.expected_date,this.name,value);
      this.$emit("click-input", this.name, {
        start_date,
        end_date
      });
      this.dateShow = false;
    },
    onDateClose() {
      this.dateShow = false;
    },
  }
};
</script>